<template>
  <div class="card bg-white p-3 mt-3 fs-xl">
    <div class="card-header flex flex-ai-center pb-3">
      <i class="iconfont fs-xl" :class="`icon-${icon}`"></i>
      <div class="flex-1 px-2">{{title}}</div>
      <div class="iconfont icon-meun"></div>
    </div>
    <div class="card-body pt-3">
      <div class="nav">
        <div
          class="nav-item"
          :class="{active:active == index}"
          v-for="(item,index) in categories"
          :key="index"
          @click="$refs.list.$swiper.slideTo(index)"
        >
          <div class="nav-link">{{item.name}}</div>
        </div>
      </div>
      <div class="py-2">
        <swiper
          :options="{autoHeight:true}"
          ref="list"
          @slide-change="()=>active = $refs.list.$swiper.realIndex"
        >
          <swiper-slide v-for="(category,index) in categories" :key="index">
            <slot name="items" :category="category"></slot>
          </swiper-slide>
        </swiper>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    title: { type: String, required: true },
    icon: { type: String, required: true },
    categories: { type: Array }
  },
  data() {
    return {
      active: 0
    };
  }
};
</script>

<style lang="scss"scoped>
@import "../assets/style/variables";
.card {
  border-top: 1px solid map-get($colors, "border");
  border-bottom: 1px solid map-get($colors, "border");
  .card-header {
    border-bottom: 1px solid map-get($colors, "border");
  }
}
</style>